import 'package:FineArt/core/api/home_api.dart';
import 'package:FineArt/core/widget/web_view_page.dart';
import 'package:FineArt/page/imageview/RoundCheckBoxCourse.dart';
import 'package:FineArt/utils/log_util.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class CheckImage extends StatelessWidget {
  //
  final String url;
  final bool isShowCheck;
  bool isCheck;
  final double height;

  final double width;
  Function checkChange;

  Function onTap;

  CheckImage(
      {Key key,
      this.url,
      this.isShowCheck = false,
      this.isCheck = false,
      this.height = 100,
      this.width = 100,
      this.checkChange,
      this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
      return InkWell(
        onTap: () {
          if (!isShowCheck) onTap();
        },
        child: Stack(children: [
          Image(
              fit: BoxFit.contain,
              width: width,
              height: height,
              image: CachedNetworkImageProvider(
                url,
              )),
          Positioned(
            child: isShowCheck
                ? RoundCheckBoxCourse(
                    value: isCheck,
                    onChanged: (bool val) {
                      checkChange(val);
                      // setState((){
                      //   isCheck=val;
                      // });
                    },
                  )
                : SizedBox(
                    width: 19,
                    height: 19,
                  ),
            bottom: 1,
            right: 1,
          )
        ]),
      );

      // Here i can use size.width but use double.infinity because both work as a same
    });
  }
}
